package com.earnings.okhttputils.utils.ui.activity.user;

import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.earnings.R;
import com.earnings.okhttputils.utils.OkHttp.OkHttpUtils;
import com.earnings.okhttputils.utils.OkHttp.utils.ToastUtils;
import com.earnings.okhttputils.utils.UrlConstant.HttpUrl;
import com.earnings.okhttputils.utils.bean.UserStatisticsData;
import com.earnings.okhttputils.utils.god.GodLeftHandBaseActivity;
import com.earnings.okhttputils.utils.https.HttpMap;
import com.earnings.okhttputils.utils.https.HttpObjectCallback;
import com.earnings.okhttputils.utils.utils.CommonUtil;

import java.util.Map;

/*
个人统计
 */
public class UserStatisticsActivity extends GodLeftHandBaseActivity {

    private ImageView head;

    private TextView nickname, phone, totalmoney, richget, public_gift;

    @Override
    protected int onCreateLayoutId() {
        return R.layout.activity_user_statistics;
    }

    @Override
    protected void init() {
        setTopStyleView();
        setTitle("个人统计");

        head = (ImageView) findViewById(R.id.head);
        nickname = (TextView) findViewById(R.id.nickname);
        phone = (TextView) findViewById(R.id.phone);
        totalmoney = (TextView) findViewById(R.id.totalmoney);
        richget = (TextView) findViewById(R.id.richget);
        public_gift = (TextView) findViewById(R.id.public_gift);

        Glide.with(this).load(CommonUtil.getUser().getHead_pic()).error(R.mipmap.head_icon).into(head);


        phone.setText(CommonUtil.getUser().getPhone());
        nickname.setText(CommonUtil.getUser().getNickname());
        loadData();
    }


//    @Override
//    public void onClick(View v) {
//        int i = v.getId();
//        if (i == R.id.top_right_tv) {
//            finish();
//
//        }
//    }

    /*
               查询累计消费
                */
    public void loadData() {
        Map map = new HttpMap(getContext());
        OkHttpUtils.post().url(HttpUrl.USER_STATISTICS_URL).params(map).build().execute(new HttpObjectCallback<UserStatisticsData>(getContext()) {

            @Override
            public void onSuccess(UserStatisticsData object, String msg) {
                totalmoney.setText(object.getTotalmoney());
                richget.setText(object.getRichget());
                public_gift.setText(object.getPublic_gift());

                //  showToast( msg );
            }

            @Override
            public void onFail(int code, String msg) {
                ToastUtils.showToast(getContext(), msg);
            }

        });


    }
}